let Remote = function (socket) {
    let game;
    let bindEvents = function () {
        socket.on("init", function (data) {
            start(data.type, data.dir);
        });

        socket.on("next", function (data) {
            game.performNext(data.type, data.dir);
        });

        socket.on("rotate", function (data) {
            game.rotate();
        });

        socket.on("right", function (data) {
            game.right();
        });

        socket.on("down", function (data) {
            game.down();
        });

        socket.on("left", function (data) {
            game.left();
        });

        socket.on("fall", function (data) {
            game.fall();
        });

        socket.on("fixed", function (data) {
            game.fixed();
        });

        socket.on("line", function (data) {
            game.checkClear();
            game.addScore(data);
        });

        socket.on("time", function (data) {
            game.setTime(data);
        });

        socket.on("lose", function (data) {
            game.gameOver(false);
        });

        socket.on("addTailLines", function (data) {
            game.addTailLines(data);
        });
    };

    let start = function (type, dir) {
        let domes = {
            gameDiv: document.getElementById("remote-game"),
            nextDiv: document.getElementById("remote-next"),
            timeDiv: document.getElementById("remote-time"),
            scoreDiv: document.getElementById("remote-score"),
            resultDiv: document.getElementById("remote-game-over"),
        };
        game = new Game();
        game.init(domes, type, dir);
    };

    bindEvents();
};
